﻿<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>支票申请列表信息</title>
    <link rel="stylesheet" type="text/css" href="../Content/Css/OperaMasksUI/default/om-all.css" />
    <link rel="stylesheet" type="text/css" href="../Content/Css/list.css" />
    <script type="text/javascript" src="../Scripts/jquery.1.6.3.min.js"></script>
    <script type="text/javascript" src="../Scripts/json2.js"></script>
    <script type="text/javascript" src="../Scripts/common.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/operamasks-ui.min.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/jquery.form.js"></script>
    <script type="text/javascript" src="../Scripts/OperaMasksUI/Plugin/om-yj-container.js"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/jquery.artDialog.js?skin=default"></script>
    <script type="text/javascript" src="../Scripts/Plugin/artDialog4.1.7/plugins/iframeTools.js"></script>
    <script type="text/javascript">
        var detailPanel, listGrid, colData, searchPanel, defaultSort, defaultWhere, validatorForm, submitForm, currentUID, currentDept, currentSelectDept, currentDeptName, currentWhere = '', currentGIndex = -1, genRenderCheckbox, genRenderDateformat;
        var showSearchPanel, showToolBar, showDetialForm, controlBtn, oldRowData, detailForm, goOn = true, DoFlag = true, ifh;
        var actionRoot = "../handler/ajax.ashx?type=AjaxSystem", comboxBankData = [], comboxTypeData = [], comboxStatusData = [], genRenderDateformat, genRenderDateformatSS;

        $(document).ready(function () {
            $.ajax({
                cache: false, async: false,
                url: '../handler/ajax.ashx?type=AjaxSystem&method=loginIn',
                dataType: 'json', type: 'post',
                beforeSend: function () {
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在加载用户信息,请稍后...'
                    });
                },
                complete: function () {
                    $.omMessageBox.waiting("close");
                },
                success: function (data) {
                    if (data.IsError) {
                        goOn = false;
                        $.omMessageBox.alert({
                            content: '发现系统错误,请重新登录<BR>错误码：' + data.Message,
                            onClose: function () {
                                window.top.location.href = decodeURIComponent("../Index.aspx");
                            }
                        });
                    }
                    else {
                        goOn = true;
                        currentUID = data.Data.userid;
                        currentDept = data.Data.deptid;
                        currentDeptName = data.Data.deptname;
                        if (currentDept.split(',').length == 1) {
                            $("#DeptName").attr("disabled", true)
                            $("#openSelect").attr("disabled",true)
                        }
                    }
                },
                error: function (result) {
                    goOn = false;
                    $.omMessageBox.alert({
                        content: '发现系统错误,请重新登录<BR>错误码：' + result.status,
                        onClose: function () {
                            window.top.location.href = decodeURIComponent("Index.aspx");
                        }
                    });
                }
            });
            if (goOn) {
                $.ajax({
                    cache: false, async: false,
                    url: '../handler/ajax.ashx?type=AjaxSystem&method=getAuthInfo',
                    dataType: 'json', type: 'post',
                    data: { menuID: getQueryStringByName("menuid") },
                    beforeSend: function () {
                        $.omMessageBox.waiting({
                            title: '请等待',
                            content: '服务器正在加载用户信息,请稍后...'
                        });
                    },
                    complete: function () {
                        $.omMessageBox.waiting("close");
                    },
                    success: function (data) {
                        if (data.IsError) {
                            goOn = false;
                            $.omMessageBox.alert({
                                content: '错误<BR>：' + data.Message,
                                onClose: function () {
                                    window.top.location.href = decodeURIComponent("../Index.aspx");
                                }
                            });
                        }
                        else {
                            goOn = true;
                            //判断是否有查看权限
                            if (checkString(data.Data.userData, "查看所有") > -1) {
                                currentSelectDept = " AND 1=1 ";
                                currentWhere = " AND 1=1 ";
                            }
                            else {
                                if (checkString(data.Data.userData, "查看部门") > -1) {
                                    currentSelectDept = " AND EXISTS ( SELECT 1 FROM vUserDepartment U WHERE U.UserID = " + currentUID + " AND A.Name = U.DepartmentName) ";
                                    currentWhere = " AND EXISTS ( SELECT 1 FROM vUserDepartment U WHERE U.UserID = " + currentUID + " AND A.DeptName = U.DepartmentName) ";
                                }
                                else {
                                    currentSelectDept = " AND 1=0 ";
                                    currentWhere = " AND 1=0 ";
                                }
                            }
                            //if(checkString(data.Data.userData,"提交") > -1){
                            //    $("#button-submit").hide();
                            //}
                            //if (checkString(data.Data.userData, "撤销") > -1) {
                            //    $("#button-undo").hide();
                            //}
                        }
                    },
                    error: function (result) {
                        goOn = false;
                        $.omMessageBox.alert({
                            content: '错误<BR>：' + result.status,
                            onClose: function () {
                                window.top.location.href = decodeURIComponent("../Index.aspx");
                            }
                        });
                    }
                });
            }

            var element = $('body').omBorderLayout({
                fit: true,
                spacing: 0,
                panels: [
                {
                    id: "center-panel",
                    header: false,
                    title: "中间模块",
                    region: "center"
                }, {
                    id: "west-panel",
                    resizable: true,
                    collapsible: true,
                    title: "<span style='color:#15428B;font-weight: bold;padding:6px;'>查询条件</span>",
                    region: "west",
                    width: 230
                },
                {
                    id: "south-panel",
                    region: "south",
                    header: false,
                    resizable: false,
                    collapsible: false,
                    height: 50
                }
                ]
            });
            detailForm = $('#viewForm');
            $("#CheckApplyDate", detailForm).omCalendar();
            $.ajax({
                cache: false, async: false,
                url: '../Handler/combox.ashx?view=vBaseData',
                dataType: 'json', type: 'post',
                beforeSend: function () {
                    $.omMessageBox.waiting({
                        title: '请等待',
                        content: '服务器正在加载银行信息,请稍后...'
                    });
                },
                complete: function () {
                    $.omMessageBox.waiting("close");
                },
                success: function (data) {
                    comboxStatusData = []
                    $.each(data, function (index, value) {
                        switch (value.Type) {
                            case '支票申请状态':
                                comboxStatusData.push({ name: value.Name, code: value.Code, type: value.Type });
                                return true;
                            default:
                                return true;
                        }
                    })
                },
                error: function (result) {
                    goOn = false;
                    $.omMessageBox.alert({
                        content: '发现系统错误,请重新登录<BR>错误码：' + result.status
                    });
                }
            });
            $('#CheckApplyStatus', detailForm).omCombo({
                dataSource: comboxStatusData,
                valueField: 'code',
                optionField: 'name',
                disabled: true,
                inputField: 'name'
            });
            $(":input", detailForm).change(function () { controlBtn(detailForm, 'disable', 'disable', 'disable', 'enable', 'enable'); detailForm.data('changed', true); });
            validatorForm = $('#viewForm').validate({
                errorContainer: "#errorMessages",
                errorLabelContainer: "#errorMessages",
                wrapper: "span",
                errorClass: "omError",
                rules: {
                    DeptCode: { required: true },
                    Qty: { required: true, digits: true },
                    CheckApplyDate: { required: true}
                },
                messages: {
                    DeptCode: { required: "[部门名称]不能为空" },
                    Qty: { required: "[申请数量]不能为空", digits: "[申请数量]必须是数字" },
                    CheckApplyDate: { required: "[申请时间]不能为空" }
                }
            });
            showSearchPanel();
            showToolBar(detailForm);
            showDetialForm("数据明细", "");
            controlBtn(detailForm, 'enable', 'disable', 'enable', 'disable', 'disable');
            colData = [
                { header: '申请号码', name: 'CheckApplyNo', width: 200, align: 'center' },
                { header: '申请状态', name: 'CheckApplyStatus', width: 120, align: 'center' },
                { header: '部门编码', name: 'DeptCode', width: 120, align: 'center' },
                { header: '部门名称', name: 'DeptName', width: 150, align: 'center' },
                { header: '数量', name: 'QTY', width: 80, align: 'center' },
                { header: '备注', name: 'Note', width: 80, align: 'center' },
                { header: '申请时间', name: 'CheckApplyDate', width: 200, align: 'center', renderer: genRenderDateformatSS },
                { header: '提交', name: 'IsCommit', width: 30, align: 'center', renderer: genRenderCheckbox },
                { header: '提交时间', name: 'CommitDate', width: 200, align: 'center', renderer: genRenderDateformat },
                { header: '提交人', name: 'UserCommit', width: 80, align: 'center' },
                { header: '分配', name: 'IsAllocate', width: 30, align: 'center', renderer: genRenderCheckbox },
                { header: '分配时间', name: 'AllocateDate', width: 200, align: 'center', renderer: genRenderDateformat },
                { header: '分配人', name: 'UserAllocate', width: 80, align: 'center' },
                { header: '确认', name: 'IsConfirm', width: 30, align: 'center', renderer: genRenderCheckbox },
                { header: '确认时间', name: 'ConfirmDate', width: 200, align: 'center', renderer: genRenderDateformat },
                { header: '确认人', name: 'UserConfirm', width: 80, align: 'center' },
                { header: '创建人', name: 'UserCreate', width: 100, align: 'center' },
                { header: '创建时间', name: 'CreateDate', width: 200, align: 'center',renderer: genRenderDateformat},
                { header: '修改人', name: 'UserModify', width: 100, align: 'center' },
                { header: '修改时间', name: 'ModifyDate', width: 200, align: 'center',renderer: genRenderDateformat}
            ];
            defaultSort = { sortby: 'UID', sortdir: 'ASC' };
            defaultWhere = { where: " 1=1 " };
            listGrid = $('#listgrid').omGrid({
                width: 2000,
                height: 'fit',
                autoFit: true,
                title: '支票申请列表',
                onRowClick: function (rowIndex, rowData, event) {
                    if (detailForm.data('changed')) {
                        $.omMessageBox.alert({
                            type: 'warning',
                            title: '友情提醒',
                            content: '请先保存修改的数据'
                        });
                    }
                    else {
                        currentGIndex = rowIndex;
                        oldRowData = rowData || {};
                        showDetialForm("数据明细", rowData);
                    }
                },
                singleSelect: false,
                editMode: "insert",
                limit: 20,
                extraData: $.extend(defaultWhere, defaultSort),
                dataSource: '',
                colModel: colData
            });
            $("#openSelect").click(function () {
                var openSql = " SELECT * FROM tDepartment A ";
                art.dialog.open('DeptSelect.aspx?vsql=' + openSql + '&para=' + " 1=1 " + currentSelectDept, {
                    id: 'selectDiv', width: 600, height: 400, title: '选择部门', lock: true,
                    close: function () {
                        var bValue = art.dialog.data('selectValue');
                        if (bValue !== undefined) {
                            $('#DeptCode').val(bValue.split('$')[1]);
                            $('#DeptName').val(bValue.split('$')[2]);
                        }
                        else {
                            $('#DeptCode').val("");
                            $('#DeptName').val("");
                        }
                    }
                }, false);
            })
        });

        genRenderCheckbox = function (colValue, rowData, rowIndex) {
            if (colValue) {
                return '<input type="checkbox" id="00" checked="checked" disabled="disabled"></input>';
            }
            return '<input type="checkbox" id="01" disabled="disabled"></input>';
        }

        genRenderDateformatSS = function (colValue, rowData, rowIndex) {
            if (colValue.length == 0 || colValue == null) {
                return '';
            }
            else {
                if (colValue.indexOf("/Date") > -1)
                    return new Date(parseInt(colValue.replace("/Date(", "").replace(")/", ""), 10)).Format("yyyy-MM-dd");
                else
                    return colValue;
            }
        }

        genRenderDateformat = function (colValue, rowData, rowIndex) {
            if (colValue.length == 0 || colValue == null) {
                return '';
            }
            else {
                if (colValue.indexOf("/Date") > -1)
                    return new Date(parseInt(colValue.replace("/Date(", "").replace(")/", ""), 10)).Format("yyyy-MM-dd hh:mm");
                else
                    return colValue;
            }
        }

        showToolBar = function (form) {
            $('span#button-new', form).omButton({
                icons: { left: '../Content/Images/List/add.png' }, width: 80,
                onClick: function () {
                    if (detailPanel) {
                        $('#UID', detailForm).val("0");
                        $.ajax({
                            cache: false, async: false,
                            url: '../handler/ajax.ashx?type=AjaxSystem&method=GetSeqNo',
                            dataType: 'json', type: 'post',
                            data: { DoType: 'CHECKAPPLY', PT: 0 },
                            beforeSend: function () {
                                $.omMessageBox.waiting({
                                    title: '请等待',
                                    content: '服务器正在加载用户信息,请稍后...'
                                });
                            },
                            complete: function () {$.omMessageBox.waiting("close");},
                            success: function (data) {
                                if (data.IsError) {
                                    $.omMessageBox.alert({
                                        content: '错误<BR>：' + data.Message,
                                        onClose: function () {
                                            window.top.location.href = decodeURIComponent("../Index.aspx");
                                        }
                                    });
                                }
                                else {
                                    $('#CheckApplyNo', detailForm).val(data.Data + "-预配");
                                }
                            },
                            error: function (result) {}
                        })
                        $('#Note', detailForm).val("");
                        $('#CheckApplyStatus', detailForm).omCombo("value", 1);
                        $('#CheckApplyDate', detailForm).val((new Date()).Format("yyyy-MM-dd"));
                        $('#DeptCode', detailForm).val(currentDept.split(',')[0]);
                        $('#DeptName', detailForm).val(currentDeptName.split(',')[0]);
                        $('#CheckApplyNo', detailForm).focus();
                        detailForm.data('changed', true);
                        controlBtn(form, 'disable', 'disable', 'disable', 'enable', 'enable');
                    }
                }
            });
            $('span#button-copy', form).omButton({
                icons: { left: '../Content/Images/List/copy.png' }, width: 80,
                onClick: function () {
                    if (detailPanel) {
                        $('#UID', detailForm).val("0");
                        $.ajax({
                            cache: false, async: false,
                            url: '../handler/ajax.ashx?type=AjaxSystem&method=GetSeqNo',
                            dataType: 'json', type: 'post',
                            data: { DoType: 'CHECKAPPLY', PT: 0 },
                            beforeSend: function () {
                                $.omMessageBox.waiting({
                                    title: '请等待',
                                    content: '服务器正在加载用户信息,请稍后...'
                                });
                            },
                            complete: function () { $.omMessageBox.waiting("close"); },
                            success: function (data) {
                                if (data.IsError) {
                                    $.omMessageBox.alert({
                                        content: '错误<BR>：' + data.Message,
                                        onClose: function () {
                                            window.top.location.href = decodeURIComponent("../Index.aspx");
                                        }
                                    });
                                }
                                else {
                                    $('#CheckApplyNo', detailForm).val(data.Data + "-预配");
                                    $("#CheckApplyNo", detailForm).focus();
                                }
                            },
                            error: function (result) { }
                        })
                        controlBtn(form, 'disable', 'disable', 'disable', 'enable', 'enable');
                    }
                }
            });
            $('span#button-delete', form).omButton({
                icons: { left: '../Content/Images/List/delete.png' }, width: 80,
                onClick: function () {
                    if ($("#UID").val() != "0" && currentGIndex > -1) {
                        $.omMessageBox.confirm({
                            title:'确认删除',
                            content:'确定要删除吗？',
                            onClose: function (v) {
                                if (v) {
                                    $.ajax({
                                        cache: false, async: false,
                                        url: '../handler/ajax.ashx?type=AjaxSystem&method=RemoveCheckApply',
                                        dataType: 'json', type: 'post',
                                        data: { UID: $("#UID").val(), USERID: currentUID },
                                        beforeSend: function () {
                                            $.omMessageBox.waiting({
                                                title: '请等待',
                                                content: '系统正在删除信息,请稍后...'
                                            });
                                        },
                                        complete: function () {
                                            $.omMessageBox.waiting("close");
                                        },
                                        success: function (data) {
                                            if (data.IsError) {
                                                $.omMessageBox.alert({
                                                    content: '错误：' + data.Message
                                                });
                                            }
                                            else {
                                                $.omMessageBox.alert({
                                                    content: data.Message,
                                                    onClose: function () {
                                                        if (listGrid[0].rows.length > 0 && currentGIndex >= 0) {
                                                            $("input[type='text']", form).each(function (index, element) {
                                                                $(this).val("");
                                                            });
                                                            listGrid.omGrid("deleteRow", currentGIndex);
                                                            listGrid.omGrid('saveChanges');
                                                            listGrid.omGrid("refresh");
                                                            controlBtn(detailForm, 'enable', 'disable', 'enable', 'disable', 'disable');
                                                        }
                                                    }
                                                });
                                            }
                                        },
                                        error: function (result) {
                                            $.omMessageBox.alert({
                                                content: '发现系统错误,请重新登录<BR>错误码：' + result.status
                                            });
                                        }
                                    });
                                }
                            }
                        });
                    }
                }
            });
            $('span#button-save', form).omButton({
                icons: { left: '../Content/Images/List/accept.png' }, width: 80,
                onClick: function () {
                    var gridLen = listGrid[0].rows.length;
                    if (currentUID == "0") {
                        $.omMessageBox.alert({
                            type: 'warning',
                            title: '友情提醒',
                            content: '您登录已超时,请重新登录继续操作...',
                            onClose: function () {
                                window.top.location.href = decodeURIComponent("../Index.aspx")
                            }
                        });
                    }
                    else {
                        if (!detailForm.data('changed')) {
                            $.omMessageBox.alert({
                                type: 'warning',
                                title: '友情提醒',
                                content: '表单数据没有更改无需保存'
                            });
                        }
                        else {
                            if (validatorForm.form()) {
                                if ($("#UID").val() == "0") {
                                    DoFlag = true;
                                    detailForm.attr("action", actionRoot + "&method=AddCheckApply");
                                }
                                else {
                                    DoFlag = false;
                                    detailForm.attr("action", actionRoot + "&method=UpdateCheckApply");
                                }
                                submitForm(detailForm, function (data) {
                                    if (data.IsError) {
                                        $.omMessageBox.alert({
                                            type: 'error',
                                            content: '发现系统错误<BR>错误码：' + data.Message,
                                            onClose: function () {
                                                $("#CheckApplyNo", detailForm).focus();
                                            }
                                        });
                                    }
                                    else {
                                        if (!DoFlag && currentGIndex >= 0) {
                                            listGrid.omGrid("deleteRow", currentGIndex);
                                        }
                                        if (gridLen > 0){
                                            listGrid.omGrid("insertRow", 0, data.Data, true);
                                        }
                                        $.omMessageBox.alert({
                                            type: 'success',
                                            content: '数据保存成功',
                                            onClose: function () {
                                                if (gridLen > 0) {
                                                    listGrid.omGrid('saveChanges');
                                                    listGrid.omGrid("refresh");
                                                }
                                                else {
                                                    listGrid.omGrid({
                                                        extraData: $.extend({ where: defaultWhere.where + " AND UID= '"+ data.Data.UID +"' " }, defaultSort),
                                                        dataSource: '../Handler/grid.ashx?view=vCheckApply'
                                                    });
                                                }
                                            }
                                        })
                                        currentGIndex = 0;  //默认第一行数据
                                        detailForm.data('changed', false);
                                        controlBtn(form, 'enable', 'enable', 'disable', 'disable', 'disable');
                                    }
                                });
                            }
                        }
                    }
                }
            });
            $('span#button-cancel', form).omButton({
                icons: { left: '../Content/Images/List/cross.png' }, width: 80,
                onClick: function () {
                    detailForm.data('changed', false);
                    showDetialForm("数据明细", oldRowData);
                    if ($("#UID").val() == "0") {
                        controlBtn(form, 'enable', 'disable', 'disable', 'disable', 'disable');
                    }
                    else {
                        controlBtn(form, 'enable', 'enable', 'disable', 'disable', 'disable');
                    }
                }
            });
        }

        showSearchPanel = function () {
            $("#button-search").click(function () {
                var custWhere = '';
                custWhere += ' AND CheckApplyNo LIKE ' + '\'%' + $("#search-panel input[id='CheckApplyNo']").val() + '%\'';
                listGrid.omGrid({
                    extraData: $.extend({ where: defaultWhere.where + currentWhere + custWhere }, defaultSort),
                    dataSource: '../Handler/grid.ashx?view=vCheckApply'
                });
            });
            $('#button-clear').click(function () {
                $("div[id='search-panel'] input").val("");
            });
            $('#button-export').click(function () {
                $("div[id='search-panel'] input").val("");
            });
            $('#button-submit').click(function () {
                var selectRow = listGrid.omGrid("getSelections", true);
                if (selectRow.length > 0) {
                    var tempuid = '',tempuidcount = 0;
                    $.each(selectRow, function (index, value) {
                        tempuid += value.UID + ',';
                        tempuidcount += 1;
                    });
                    $.ajax({
                        cache: false, async: false,
                        url: '../handler/ajax.ashx?type=AjaxSystem&method=SubmitCheckApply',
                        dataType: 'json', type: 'post',
                        data: { UID: tempuid.substring(0,tempuid.length-1), USERID: currentUID },
                        beforeSend: function () {
                            $.omMessageBox.waiting({
                                title: '请等待',
                                content: '系统正在提交,请稍后...'
                            });
                        },
                        complete: function () {
                            $.omMessageBox.waiting("close");
                        },
                        success: function (data) {
                            if (data.IsError) {
                                $.omMessageBox.alert({
                                    content: '错误：' + data.Message
                                });
                            }
                            else {
                                art.dialog.data('showValue', JSON2.parse(data.Data))
                                art.dialog.open('ShowBox.aspx', {
                                    id: 'selectDiv', width: 650, height: 400, title: '操作结果', lock: true,
                                    close: function () {
                                        listGrid.omGrid("reload");
                                    }
                                }, false);
                            }
                        },
                        error: function (result) {
                            $.omMessageBox.alert({
                                content: '发现系统错误,请重新登录<BR>错误码：' + result.status
                            });
                        }
                    });
                }
                else {
                    $.omMessageBox.alert({
                        content: '请至少选择一条数据',
                        onClose: function () { }
                    });
                }
            });
            $('#button-undo').click(function () {
                var selectundoRow = listGrid.omGrid("getSelections", true);
                if (selectundoRow.length > 0) {
                    var tempuid = '', tempuidcount = 0;
                    $.each(selectundoRow, function (index, value) {
                        tempuid += value.UID + ',';
                        tempuidcount += 1;
                    });
                    $.ajax({
                        cache: false, async: false,
                        url: '../handler/ajax.ashx?type=AjaxSystem&method=UndoCheckApply',
                        dataType: 'json', type: 'post',
                        data: { UID: tempuid.substring(0, tempuid.length - 1), USERID: currentUID },
                        beforeSend: function () {
                            $.omMessageBox.waiting({
                                title: '请等待',
                                content: '系统正在提交,请稍后...'
                            });
                        },
                        complete: function () {
                            $.omMessageBox.waiting("close");
                        },
                        success: function (data) {
                            if (data.IsError) {
                                $.omMessageBox.alert({
                                    content: '错误：' + data.Message
                                });
                            }
                            else {
                                art.dialog.data('showValue', JSON2.parse(data.Data))
                                art.dialog.open('ShowBox.aspx', {
                                    id: 'selectDiv', width: 650, height: 400, title: '操作结果', lock: true,
                                    close: function () {
                                        listGrid.omGrid("reload");
                                    }
                                }, false);
                            } 
                        },
                        error: function (result) {
                            $.omMessageBox.alert({
                                content: '发现系统错误,请重新登录<BR>错误码：' + result.status
                            });
                        }
                    });
                }
                else {
                    $.omMessageBox.alert({
                        content: '请至少选择一条数据',
                        onClose: function () { }
                    });
                }
            });
        };

        showDetialForm = function (title, rowData) {
            if (detailPanel) {
                $("input[type=text]", detailPanel).val("");
                detailPanel.omPanel("open");
            }
            else {
                detailPanel = $('#detail-form').omPanel({
                    width: 'fit',
                    title: "<span style='color:#15428B;font-weight: bold;padding:6px;'>" + title + "</span>",
                    collapsed: false,
                    collapsible: false,
                    closable: false
                });
            }
            validatorForm.resetForm();
            rowData = rowData || {};
            controlBtn(detailForm, 'enable', 'enable', 'enable', 'disable', 'disable');
            $.each(rowData, function (n, value) {
                if (n == 'CheckApplyDate')
                    $("input[id='" + n + "']", detailPanel).val(value == null ? '' : new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10)).Format("yyyy-MM-dd"));
                else {
                    if (n == 'CheckApplyStatus') {
                        $('#' + n, detailForm).omCombo("value", value);
                    }
                    else {
                        $("input[id='" + n + "']", detailPanel).val(value);
                    }
                }
            })
        };

        controlBtn = function (form, a, b, c, d, e) {
            if (form) {
                $('span#button-new', form).omButton(a)
                $('span#button-copy', form).omButton(b)
                $('span#button-delete', form).omButton(c)
                $('span#button-save', form).omButton(d)
                $('span#button-cancel', form).omButton(e)
            }
        }

        submitForm = function (mainform, success, error) {
            if (!mainform)
                return false;
            else {
                mainform.ajaxSubmit({
                    type: "POST",
                    dataType: 'json',
                    success: success,
                    clearForm: false,
                    beforeSubmit: function (formData, jqForm, options) {
                        $(":checkbox,:radio", jqForm).each(function () {
                            if (!existInFormData(formData, this.name)) {
                                formData.push({ name: this.name, type: this.type, value: this.checked });
                            }
                        });
                        for (var i = 0, l = formData.length; i < l; i++) {
                            var o = formData[i];
                            if (o.type == "checkbox" || o.type == "radio") {
                                o.value = $("[name=" + o.name + "]", jqForm)[0].checked ? "true" : "false";
                            }
                        }
                    },
                    beforeSend: function (a, b, c) {
                        $.omMessageBox.waiting({
                            title: '正在保存数据中...',
                            content: '服务器正在处理请求......'
                        });
                    },
                    complete: function () {
                        $.omMessageBox.waiting("close")
                    },
                    error: function (result) {
                        $.omMessageBox.waiting("close")
                        $.omMessageBox.alert({
                            content: '发现系统错误 <BR>错误码：' + result.status
                        });
                    }
                });
            }
        }

        function existInFormData(formData, name) {
            for (var i = 0, l = formData.length; i < l; i++) {
                var o = formData[i];
                if (o.name == name) return true;
            }
            return false;
        }
    </script>
</head>
<body>
    <div id="west-panel" class="westpanel">
        <div id="search-panel">
            <table>
                <tr>
                    <td style="width: 60px" align="right">
                        <span class="label">申请号码</span>
                    </td>
                    <td>
                        <input type="text" class="input-text" id="CheckApplyNo" />
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div id="center-panel">
        <div id="detail-form">
            <form id="viewForm">
                <div id="errorMessages" class="error"></div>
                <table>
                    <tr style="display: none;">
                        <td colspan="8">
                            <input name="UID" id="UID" value="0" />
                        </td>
                    </tr>
                    <tr>
                        <td align="right" style="width: 50px; color: red;">申请号码</td>
                        <td align="left" style="width: 130px">
                            <input type="text" class="input-text" name="CheckApplyNo" id="CheckApplyNo" disabled="disabled" style="width: 100%;" /></td>
                        <td align="right" style="width: 80px; margin-left: 10px; color: red;">申请时间</td>
                        <td align="left" style="width: 130px">
                            <input type="text" class="input-text" name="CheckApplyDate" id="CheckApplyDate" value="" style="width: 100%;" />
                        </td>
                        <td align="right" style="width: 80px; margin-left: 10px;">支票状态</td>
                        <td align="left" style="width: 130px">
                            <input type="text" class="input-text" name="CheckApplyStatus" id="CheckApplyStatus" style="width: 100%;" /></td>
                        <td align="right" style="width: 80px; margin-left: 10px; color: red;">申请部门</td>
                        <td align="left" style="width: 170px">
                            <input type="text" name="DeptCode" id="DeptCode" style="width:0px;display:none;" />
                            <div class="sw_b">
                                <input type="text" name="DeptName" id="DeptName" value="" /><input id="openSelect" class="sw_qbtn" type="button" />
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" style="width: 50px; color: red;">申请数量</td>
                        <td align="left" style="width: 130px">
                            <input type="text" class="input-text" name="Qty" id="Qty" style="width: 100%;" value="1" /></td>
                        <td align="right" style="width: 80px; margin-left: 10px;">备注</td>
                        <td align="left" style="width: 210px" colspan="3">
                            <input type="text" class="input-text" name="Note" id="Note" style="width: 100%;" maxlength="100" />
                        </td>
                        <td align="right" style="width: 50px"></td>
                        <td align="left" style="width: 130px"></td>
                    </tr>
                    <tr>
                        <td align="left" colspan="8">
                            <span id="button-new">新增</span>
                            <span id="button-copy">复制</span>
                            <span id="button-delete">删除</span>
                            <span id="button-save">保存</span>
                            <span id="button-cancel">取消</span>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
        <table id="listgrid"></table>
    </div>
    <div id="south-panel">
        <table style="margin-top: 5px; margin-left: 20px;">
            <tr>
                <td>
                    <input id="button-search" type="button" class="btnCss" value="搜    索" />
                    <input id="button-clear" type="button" class="btnCss" value="清    空" style="margin-left: 20px;" />
                    <input id="button-export" type="button" class="btnCss" value="导    出" style="margin-left: 20px;" />
                    <input id="button-submit" type="button" class="btnCss" value="提    交" style="margin-left: 20px;" />
                    <input id="button-undo" type="button" class="btnCss" value="撤    销" style="margin-left: 20px;" />
                </td>
            </tr>
        </table>
    </div>
</body>
</html>
